package com.nanbei.tree;

import org.junit.Test;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: BaoShan.li
 * @Created: 2023/12/18 14:27
 */
public class BSTreeTest {

    /**
     *              10
     *            /    \
     *           5      15
     *          / \    /  \
     *         2  8   13   18
     *               /
     *              12
     */


    @Test
    public void test1(){
        BSTNode node = new BSTNode(10, "10",
                new BSTNode(5, "5", new BSTNode(2, "2"), new BSTNode(8, "8")),
                new BSTNode(15, "15", new BSTNode(13, "13",new BSTNode(12,"12"),null), new BSTNode(18, "18"))
        );

        BSTree bsTree = new BSTree(node);
        // 根据值获取元素
        Object o = bsTree.get(14);
        System.out.println(o);
        System.out.println("--------------------------");
        // 获取最大元素
        System.out.println("最大值："+bsTree.getMax());
        System.out.println("--------------------------");
        // 获取最大元素
        System.out.println("最小值："+bsTree.getMin());
        System.out.println("--------------------------");
       // boolean put = bsTree.put(9, "9");
       // System.out.println(put);
        System.out.println("--------------------------");
        System.out.println("获取当前值的前驱节点："+bsTree.predecessor(12));
        System.out.println("获取当前值的后继节点："+bsTree.successor(13));
    }
}
